
/**
 * Project Name:cats-core-impl
 * File Name:AuthAreaDao.java
 * Package Name:com.catsic.core.authArea.dao
 * Date:2014年3月24日下午3:35:53
 * Copyright (c) 2014, oa.catsic.com All Rights Reserved.
 */
 
package com.catsic.core.autharea.dao;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import com.catsic.base.BaseDao;
import com.catsic.core.entity.AuthArea;


/**
 * ClassName: AuthAreaDao
 * Description: 授权区域Dao
 * date: 2014年3月24日 下午3:35:53
 * author: yangyd
 */
public interface AuthAreaDao extends BaseDao<AuthArea, String> {
	/**
	 * findByCode:通过CODE获得授权分类.
	 * @author yangyd
	 * @param code
	 * @return
	 */
	@Query("select r from AuthArea r where r.code = ?1")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public AuthArea findByCode(String code);
	
	/**
	 * findByLikeCode:通过CODE获得授权分类列表.
	 * @author yangyd
	 * @param code
	 * @return
	 */
	@Query("select r from AuthArea r where r.code like ?1 order by r.code asc")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public List<AuthArea> findByLikeCode(String code);
	
	/**
	 * findByPcode:通过pcode获得授权分类列表.
	 * @author yangyd
	 * @param pcode
	 * @return
	 */
	@Query("select a from AuthArea a where a.parent.code = ?1 order by a.code asc")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public List<AuthArea> findByPcode(String pcode);
	
	/**
	 * findByResourceCode:通过resourceCode获得授权分类列表.
	 * @author yangyd
	 * @param resourceCode
	 * @return
	 */
	@Query("select a from AuthArea a where a.resource.code = ?1 order by a.code asc")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public List<AuthArea> findByResourceCode(String resourceCode);
	
	/**
	 * findByCodeIsNotNullAndParentIdOrderByCodeDesc:查询父节点下所有编码不为空的子节点,按编码倒叙排列
	 * @author yangyudi
	 * @param id
	 * @return
	 */
	@Query("select o from AuthArea o where o.code is not null and o.parent.id = ?1 order by o.code desc")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public List<AuthArea> findByCodeIsNotNullAndParentCodeOrderByCodeDesc(String id);
	
	/**
	 * findByPidIsNullAndResourceCodeOrderByCodeDesc:通过资源编码查询pid为空的节点
	 * @param resourceCode
	 * @return
	 */
	@Query("select o from AuthArea o where o.parent.id is null and o.resource.code = ?1 order by o.code desc")
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public List<AuthArea> findByPidIsNullAndResourceCodeOrderByCodeDesc(String resourceCode);
}
